﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Toolbox
{
    public partial class dlgAddAuthor : Form
    {
        private ToolboxDataContext dbToolbox = new ToolboxDataContext(Properties.Settings.Default.UserToolboxConnectionString);

        public dlgAddAuthor()
        {
            InitializeComponent();
        }

        private void authorBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            authorBindingSource.EndEdit();
            dbToolbox.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            authorBindingSource.AddNew();
        }

        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            authorBindingSource.RemoveCurrent();
        }

        private void dlgAddAuthor_Load(object sender, EventArgs e)
        {
            var dsA = from A in dbToolbox.Authors orderby A.Author1 select A;
            authorBindingSource.DataSource = dsA;
        }

        private void dlgAddAuthor_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("Do you want to save changes?","Alert",MessageBoxButtons.YesNo)==DialogResult.Yes)
            {
                authorBindingSource.EndEdit();
                dbToolbox.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
            }
        }
    }
}
